<template>
	<view class="my-settle-container">
		<label class="radio" @click="changeAllState">
			<radio color="#52e3fc" :checked="isFullCheck"/><text>全选</text>
		</label>
		<view class="amount-box">
			合计：<text class="amount">￥{{ checkedGoodsAmount }}</text>
		</view>
		<view class="btn-settle" @click="settlement">
			结算({{ checkedCount }})
		</view>
	</view>
</template>

<script>
	import { mapState, mapGetters,mapMutations } from 'vuex'
	export default {
		name:"my-settle",
		data() {
			return {
				timer: null,
				seconds: 3,
			}
		},
		computed: {
			...mapState('module_user', ['token']),
			...mapGetters('module_cart', ['total', 'checkedCount', 'checkedGoodsAmount']),
			isFullCheck() {
				console.log(this.total, this.checkedCount);
				return this.total === this.checkedCount
			}
		},
		methods: {
			...mapMutations(['updateNowPay', 'updateCartPay']),
			...mapMutations('module_cart', ['updateAllGoodsState']),
			...mapMutations('module_user', ['updateRedirectInfo']),
			changeAllState() {
				this.updateAllGoodsState(!this.isFullCheck)
			},
			settlement() {
				if(!this.token) {
					return this.delayNavigate()
				}
				if(this.checkedCount > 0) {
					this.updateCartPay()
					uni.navigateTo({
						url: '/subcontract/settlement/settlement'
					})
				}else {
					uni.$showMsg('请选择商品')
				}
			},
			delayNavigate() {
				this.seconds = 3
				this.showTips(this.seconds)
				this.timer = setInterval(() => {
					this.seconds--
					if(this.seconds <= 0) {
						clearInterval(this.timer)
						uni.navigateTo({
							url: '/subcontract/sign_in/sign_in',
							success: () => {
								this.updateRedirectInfo({
									openType: 'switchTab',
									from: '/pages/cart/cart'
								})
							}
						})
						return
					}
					this.showTips(this.seconds)
				}, 1000)
			},
			showTips(n) {
				uni.showToast({
					icon: 'none',
					title: '请登录后再结算!' + n + '秒之后自动跳转到登录页',
					mask: true,
					duration: 1500
				})
			}
		}
	}
</script>

<style lang="scss">
.my-settle-container {
	// position: fixed;
	// bottom: 0;
	// left: 0;
	width: 100%;
	height: 60px;
	display: flex;
	padding: 0 10px;
	align-items: center;
	box-sizing: border-box;
	background-color: #fff;
	border-top: 1px solid #f5f5f5;
	justify-content: space-between;
	.radio {
		display: flex;
		height: 29px;
		text {
			font-size: 14px;
			line-height: 29px;
		}
		radio {
			width: 29px;
			height: 29px;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	.amount-box {
		font-size: 14px;
	}
	.btn-settle {
		color: #fff;
		height: 40px;
		font-size: 14px;
		min-width: 100px;
		line-height: 40px;
		text-align: center;
		background-color: aqua;
	}
}
</style>